package com.baize.minespace.controller;


import com.baize.minespace.pojo.Likes;
import com.baize.minespace.service.LikesService;
import com.baize.minespace.utils.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 * 点赞/收藏信息表 前端控制器
 * </p>
 *
 * @author baize
 * @since 2024-04-15
 */
@RestController
@RequestMapping("/likes")
public class LikesController {
    @Autowired
    private LikesService likesService;

    @ApiModelProperty("新增点赞/收藏信息表")
    @ApiOperation(value = "新增点赞/收藏信息表", notes = "新增点赞/收藏信息表")
    @PostMapping("add")
    public Result<Boolean> addLikes(@RequestBody Likes likes){
        return Result.success(likesService.save(likes));
    }

    @ApiModelProperty("删除点赞/收藏信息表")
    @ApiOperation(value = "删除点赞/收藏信息表", notes = "删除点赞/收藏信息表")
    @GetMapping ("delete/{id}")
    public Result<Boolean> deleteLikes(@PathVariable(value = "id") Integer id) {
        return Result.success(likesService.removeById(id));
    }

    @ApiModelProperty("修改点赞/收藏信息表")
    @ApiOperation(value = "修改点赞/收藏信息表", notes = "修改点赞/收藏信息表")
    @PostMapping("update")
    public Result<Boolean> updateLikes(@RequestBody Likes likes) {
        return Result.success(likesService.updateById(likes));
    }

    @ApiModelProperty("查询点赞/收藏信息表")
    @GetMapping("select/{id}")
    public Result<Likes> selectLikes(@PathVariable(value = "id") Integer id) {
        return Result.success(likesService.getById(id));
    }

    @ApiModelProperty("分页查询点赞/收藏信息表")
    @ApiOperation(value = "分页查询点赞/收藏信息表", notes = "分页查询点赞/收藏信息表")
    @GetMapping("page/{rows}/{page}")
    public Result<IPage<Likes>> selectLikesPage(
        @PathVariable(value = "rows") Integer rows,
        @PathVariable(value = "page") Integer page,
        @RequestBody Likes likes
    ) {
        return likesService.selectLikesPage(rows, page, likes);
    }
}
